package com.zkh.myframe.server;

import com.zkh.myutils.utils.StringUtils;

/**
 * server配置实体
 */
public class ServerConfig {
	// 模块名（若当前项目为一个idea项目下的子模块，这里即指定模块名）
	private String moduleName;
	// 项目路径
	private String contextPath;
	// 端口号
	private Integer port;
	// 连接超时时间，单位ms
	private Long timeout;
	// 设置最大Post大小
	private Integer maxPostSize;
	// session失效时间，默认30，单位：分
	private Integer sessionTimeout;
	//SSL配置
	private SSLConfig SSL;
	
	public String getContextPath(String annoContextPath) {
		//配置为空，取@server注解值
		if(contextPath==null) {
			contextPath = annoContextPath;
		}
		//为空
		if(StringUtils.isEmpty(contextPath) || "/".equals(contextPath)) {
			return "";
		}
		//以/结尾，删除末尾/
		if(contextPath.endsWith("/")) {
			contextPath = contextPath.substring(0, contextPath.length()-1);
		}
		//没有以/开头，添加/
		if(!contextPath.startsWith("/")) {
			contextPath = "/" + contextPath;
		}
		return contextPath;
	}
	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}
	public Integer getPort() {
		return port;
	}
	public Integer getPort(int dftPort) {
		return port==null ? dftPort : port;
	}
	public void setPort(Integer port) {
		this.port = port;
	}
	public Long getTimeout() {
		return timeout;
	}
	public Long getTimeout(long dftTimeout) {
		return timeout==null ? dftTimeout : timeout;
	}
	public void setTimeout(Long timeout) {
		this.timeout = timeout;
	}
	public Integer getMaxPostSize() {
		return maxPostSize;
	}
	public Integer getMaxPostSize(int dftMaxPostSize) {
		return maxPostSize==null ? dftMaxPostSize : maxPostSize;
	}
	public void setMaxPostSize(Integer maxPostSize) {
		this.maxPostSize = maxPostSize;
	}
	public Integer getSessionTimeout() {
		return sessionTimeout;
	}
	public Integer getSessionTimeout(int dftSessionTimeout) {
		return sessionTimeout==null ? dftSessionTimeout : sessionTimeout;
	}
	public void setSessionTimeout(Integer sessionTimeout) {
		this.sessionTimeout = sessionTimeout;
	}
	public SSLConfig getSSL() {
		return SSL==null ? new SSLConfig() : SSL;
	}
	public void setSSL(SSLConfig SSL) {
		this.SSL = SSL;
	}
	public String getModuleName() {
		return moduleName;
	}
	public String getModuleName(String dftModuleName) {
		return StringUtils.isEmpty(moduleName) ? dftModuleName : moduleName;
	}
	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
}
